from wxauto import *
import time

class WECHAT_CLASS:
    wx = WeChat()

    def send_message(self):
        msg = "你好"
        who = "彪"
        self.wx.SendMsg(msg=msg, who=who)

    # 监听机器人
    def listen(self):
        # 添加监听对象
        self.wx.AddListenChat(who="彪")
        while True:
            time.sleep(1)
            chats = self.wx.GetListenMessage()  # 返回一个字典
            if len(chats) != 0:   # 字典判空
                for chat in chats: # chat 是字典第一个元素，是一个类
                    who = chat.who  # 哪个窗口
                    one_msgs = chats.get(chat)
                    print("who=",who, "one_msgs=", one_msgs)
                    for msg in one_msgs:
                        print("type=",msg.type, "content=", msg.content, "sender", msg.sender)
                print("*" * 20)


    def __init__(self):
        print("开始！")
        self.listen()


if __name__ == "__main__":
    obj = WECHAT_CLASS()